package com.xbongbong.pro.message.enums;/*/*/

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * MessageMenuTypeEnum
 *
 * @author GuoJun.HU
 * @since V1.0
 * @date 2019/2/19 10:45
 */
@Getter
public enum MessageMenuTypeEnum {

    // TODO message code需要和appid统一
    /**
     * crm消息推送类型
     */
    CUSTOMER(XbbRefTypeEnum.CRM.getCode(),Collections.singletonList(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode()), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getName(), "customer"),
    CUSTOMER_REMIND(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.CUSTOMER_REMIND.getCode()), XbbRefTypeEnum.CUSTOMER_REMIND.getName(), "customer_remind"),
    CUSTOMER_CONTACT(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.CONTACT.getCode()), XbbRefTypeEnum.CONTACT.getName(), "customer_contact"),
    COMMUNICATE_RECORD(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode()), XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getName(), "communicate_record"),
    OPPORTUNITY(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode()), XbbRefTypeEnum.SALES_OPPORTUNITY.getName(), "opportunity"),
    COMMUNICATE_PLAN(XbbRefTypeEnum.CRM.getCode(),Collections.singletonList(XbbRefTypeEnum.COMMUNICATE_PLAN.getCode()), XbbRefTypeEnum.COMMUNICATE_PLAN.getName(), "communicate_plan"),
    CONTRACT(XbbRefTypeEnum.CRM.getCode(), Arrays.asList(XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.CONTRACT_REMIND.getCode()), XbbRefTypeEnum.CONTRACT.getName(), "contract"),
    SALE_REPORT(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.SALES_REPORT_ENTITY.getCode()), XbbRefTypeEnum.SALES_REPORT_ENTITY.getName(), "sale_report"),
    WORK_REPORT(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.WORK_REPORT.getCode()), XbbRefTypeEnum.WORK_REPORT.getName(), "work_report"),
    SIGN_IN(XbbRefTypeEnum.CRM.getCode(), Collections.singletonList(XbbRefTypeEnum.SIGNIN.getCode()), XbbRefTypeEnum.SIGNIN.getName(), "sign_in"),
    QUOTATION(XbbRefTypeEnum.CRM.getCode(), Arrays.asList(XbbRefTypeEnum.QUOTATION.getCode(), XbbRefTypeEnum.QUOTATION_REMIND.getCode()), XbbRefTypeEnum.QUOTATION.getName(), "quotation"),
    //TODO 退货退款与jxc相关 一起处理  @author 魏荣杰  @date 2018/8/15 17:53
//    REFUND(1, Collections.singletonList(XbbRefTypeEnum.REFUND.getCode()), "退货退款消息推送", "refund"),

    /**
     * jxc消息推送类型
     */
    // TODO: 2019/1/24 jxc还没加推送设置
    SUPPLIER(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.SUPPLIER.getCode()), "enum.messageMenuType.name.supplier", "supplier"),
    SUPPLIER_CONTACT(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode()), "enum.messageMenuType.name.supplier_contact", "supplier_contact"),
    PURCHASE(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.PURCHASE.getCode()), "enum.messageMenuType.name.purchase", "purchase"),
    RETURN_PURCHASE(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.RETURNED_PURCHASE.getCode()), "enum.messageMenuType.name.return_purchase", "return_purchase"),
    ASSEMBLE(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.ASSEMBLE.getCode()), "enum.messageMenuType.name.assemble", "assemble"),
    TRANSFER(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.TRANSFER.getCode()), "enum.messageMenuType.name.transfer", "transfer"),
    INVENTORY(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.INVENTORY.getCode()), "enum.messageMenuType.name.inventory", "inventory"),
    OUTSTOCK(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.OUTSTOCK.getCode()), "enum.messageMenuType.name.outstock", "outstock"),
    INSTOCK(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.INSTOCK.getCode()), "enum.messageMenuType.name.instock", "instock"),
    WAREHOUSE(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.WAREHOUSE.getCode()), "enum.messageMenuType.name.warehouse", "warehouse"),
    STOCK(XbbRefTypeEnum.JXC.getCode(), Collections.singletonList(XbbRefTypeEnum.STOCK_PRODUCT.getCode()), "enum.messageMenuType.name.stock", "stock"),

    /**
     * 工单消息推送
     */
    WORK_ORDER(XbbRefTypeEnum.WORK_ORDER.getCode(), Collections.singletonList(XbbRefTypeEnum.WORK_ORDER.getCode()), XbbRefTypeEnum.WORK_ORDER.getName(), "work_order"),

    /**
     * 资金管理
     */
    PAYMENT(XbbRefTypeEnum.FUND_MANAGEMENT.getCode(), Collections.singletonList(XbbRefTypeEnum.PAYMENT.getCode()), "enum.messageMenuType.name.payment", "payment"),
    PAYMENT_SHEET(XbbRefTypeEnum.FUND_MANAGEMENT.getCode(), Collections.singletonList(XbbRefTypeEnum.PAYMENT_SHEET.getCode()), "enum.messageMenuType.name.payment_sheet", "paymentSheet"),
    INVOICE(XbbRefTypeEnum.FUND_MANAGEMENT.getCode(), Collections.singletonList(XbbRefTypeEnum.INVOICE.getCode()), "enum.messageMenuType.name.invoice", "invoice"),
    PAY_PLAN(XbbRefTypeEnum.FUND_MANAGEMENT.getCode(),Collections.singletonList(XbbRefTypeEnum.PAY_PLAN.getCode()),"enum.messageMenuType.name.pay_plan","payPlan"),
    PAY_PLAN_SHEET(XbbRefTypeEnum.FUND_MANAGEMENT.getCode(),Collections.singletonList(XbbRefTypeEnum.PAY_SHEET.getCode()),"enum.messageMenuType.name.pay_plan_sheet", "payPlanSheet"),
    PURCHUSE_INVOICE(XbbRefTypeEnum.FUND_MANAGEMENT.getCode(),Collections.singletonList(XbbRefTypeEnum.PURCHASE_INVOICE.getCode()),"enum.messageMenuType.name.purchuse_invoice","purchaseInvoice"),
    //PAYMENT_TASK(4,Collections.singletonList(XbbRefTypeEnum.PAYMENT_TASK.getCode()),"enum.messageMenuType.name.payment_task","paymentTask"),
//    CUSTOMER_STATEMENT_STATISTIC(4,Collections.singletonList(XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode()),"enum.messageMenuType.name.customer_statement_statistic","customerStatementStatistic"),
//    CREDIT_LIMIT(4,Collections.singletonList(XbbRefTypeEnum.CREDIT_LIMIT.getCode()),"enum.messageMenuType.name.credit_limit","creditLimit"),

    /**
     *  经销商消息推送
     */
    DISTRIBUTOR(XbbRefTypeEnum.DISTRIBUTOR.getCode(),Collections.singletonList(XbbRefTypeEnum.DISTRIBUTOR_MANAGEMENT.getCode()), XbbRefTypeEnum.DISTRIBUTOR_MANAGEMENT.getName(), "distributor"),
    DISTRIBUTOR_CONTACT(XbbRefTypeEnum.DISTRIBUTOR.getCode(), Collections.singletonList(XbbRefTypeEnum.DISTRIBUTOR_CONTACT.getCode()), XbbRefTypeEnum.DISTRIBUTOR_CONTACT.getName(), "distributor_contact"),
    DISTRIBUTOR_COMMUNICATE(XbbRefTypeEnum.DISTRIBUTOR.getCode(), Collections.singletonList(XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getCode()), XbbRefTypeEnum.DISTRIBUTOR_COMMUNICATE.getName(), "distributor_contact"),

    /**
     * 订单中心消息推送
     */
    ORDER(XbbRefTypeEnum.ORDER_CENTER.getCode(), Collections.singletonList(XbbRefTypeEnum.ORDER.getCode()), XbbRefTypeEnum.ORDER.getName(), "order"),

    /**
     * 销售线索
     */
    CLUE(XbbRefTypeEnum.MARKET_MANAGEMENT.getCode(), Collections.singletonList(XbbRefTypeEnum.CLUE.getCode()), XbbRefTypeEnum.CLUE.getName(), "clue"),

    /**
     * 新工单
     */
    WORK_ORDER_V2_CENTER(XbbRefTypeEnum.WORK_ORDER_V2_CENTER.getCode(), Collections.singletonList(XbbRefTypeEnum.WORK_ORDER_V2.getCode()), XbbRefTypeEnum.WORK_ORDER_V2.getName(), "workOrderV2"),

    /**
     * 新工单
     */
    RECEIPT_ORDER(XbbRefTypeEnum.RECEIPT_ORDER.getCode(), Collections.singletonList(XbbRefTypeEnum.RECEIPT_ORDER.getCode()), XbbRefTypeEnum.RECEIPT_ORDER.getName(), "receiptOrder"),

    /**
     * 未知消息推送
     */
    UNKNOWN(404, Collections.singletonList(0), "enum.messageMenuType.name.unknown", "unknown");
    /**
     * 枚举值 表示所属模块
     */
    private final int code;
    /**
     * 与PushTypeEnum的code要对应
     */
    private final List<Integer> subCode;
    /**
     * 枚举名称
     */
    private final String name;
    /**
     * 枚举英文名
     */
    private final String alias;

    MessageMenuTypeEnum(int code, List<Integer> subCode, String name, String alias) {
        this.code = code;
        this.subCode = subCode;
        this.name = name;
        this.alias = alias;
    }

    public static MessageMenuTypeEnum getByAlias(String alias) {
        for (MessageMenuTypeEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    public List<MessageMenuTypeEnum> getAllEnum() {
        List<MessageMenuTypeEnum> list = new ArrayList<>();
        for (MessageMenuTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    public static List<MessageMenuTypeEnum> getAllEnumByType(Integer type) {
        List<MessageMenuTypeEnum> list = new ArrayList<>();
        for (MessageMenuTypeEnum cache : values()) {
            if (cache.getCode() == type) {
                list.add(cache);
            }
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
